import { Scene } from "babylonjs";
import { AbstractBlock } from "../world/block/abstract/abstract-block";

export class CommonWrap {

	public static isPointInCircle(
		point: { a: number, b: number },
		center: { a: number, b: number },
		radius: number,
	): boolean {
		return Math.pow(point.a - center.a, 2) + Math.pow(point.b - center.b, 2) < Math.pow(radius, 2);
	}

	public static destroyBlock(scene: Scene, block: AbstractBlock): void {
		this.removeBlock(scene, block);
		block.getBox().dispose();
	}

	public static destroyBlocks(scene: Scene, blocks: Array<AbstractBlock>): void {
		if (blocks.length == 0) {
			return;
		}
		for (let i = 0; i < blocks.length; i++) {
			this.destroyBlock(scene, blocks[i]);
		}
	}

	public static removeBlock(scene: Scene, block: AbstractBlock): void {
		let box = block.getBox();
		scene.removeMesh(box);
	}

	public static removeBlocks(scene: Scene, blocks: Array<AbstractBlock>): void {
		if (blocks.length == 0) {
			return;
		}
		for (let i = 0; i < blocks.length; i++) {
			this.removeBlock(scene, blocks[i]);
		}
	}

}
